(function($){
	$.fn.j_moveMouble = function (json){
		if(!(json instanceof Object)){
			alert("数据格式错误");
			return false;
		}
		var imgWidth = json.imgWidth||json.width,imgHeight = json.imgHeight||json.height,showNum = json.showNum,list = json.list;
		var liWidth = json.width,liHeight = json.height;
		var len = list.length;
		var divWidth = showNum*(liWidth+10)+24,divHeight=liHeight+100,frameWdith=showNum*(liWidth+10),ulWidth=len*(liWidth+10);
		var string = "<em class='moveLeftIcon'></em><div class='frameUl clearfix'><ul class='clearfix'></ul></div><em class='moveRightIcon'></em>";
		var idName = $(this).attr("id");
		var cssText = "#"+idName+"{width:"+divWidth+"px;height:"+divHeight+"px;position:relative;overflow:hidden;padding:4px 0;border-radius:4px;}";
		cssText += "#"+idName+" em{position:absolute;cursor:pointer;top:"+(divHeight-21)/2+"px;width: 12px;height:21px;display:inline-block;background: url(css/i/arrow.jpg) no-repeat;}";
		cssText += "#"+idName+" .moveLeftIcon{left:0;background-position:-26px;}";
		cssText += "#"+idName+" .moveRightIcon{right:0;background-position:-39px;}";
		cssText += "#"+idName+" .frameUl{width:"+frameWdith+"px;height:"+divHeight+"px;margin-left:13px;overflow:hidden;position:relative;}";
		cssText += "#"+idName+" ul{width:"+ulWidth*2+"px;height:"+divHeight+"px;position:absolute;left:0;}";
		cssText += "#"+idName+" li{width:"+liWidth+"px;height:"+divHeight+"px;padding:0 5px;float:left;overflow:hidden;text-align:center;position:relative}";
		
		cssText += "#"+idName+" li img{border:none;}";
		//li中的样式

		cssText += "#"+idName+" .productName{width:"+(liWidth-20)+"px;height:45px;margin:0 10px;color:black;font:bold 12px arial;line-height:15px;_margin-top:3px;text-align:left;overflow:hidden;}";
		
		cssText += "#"+idName+" .price{width:"+(liWidth-20)+"px;height:30px;margin:0 10px;position:relative;text-align:left}";
		cssText += "#"+idName+" .price b{position:absolute;background:none;left:10px;top:0;width:80px;text-align:left;color:#d1d1d1;display:inline-block;line-height:30px;font-size:11px;}";
		cssText += "#"+idName+" li .tag{position:absolute;color:white;font:bold 13px/60px arial,sans-serif;text-align:center;display:block;right:0;top:0;width:50px;height:52px;background:url(css/i/bg.png) -215px -150px}";
		cssText += "#"+idName+" .price font{position:absolute;right:20px;color:rgb(193,0,0);font:bold 15px arial;line-height:30px;display:inline-block;top:0;}";

		cssText += "#"+idName+" .nowBuy,#"+idName+" .goDetail{color:white;font:12px arial;display:inline-block;float:left;height:20px;line-height:20px;_line-height:22px;overflow:hidden;background:rgb(255,125,25);width:60px;text-align:center;border-radius:4px;margin-left:10px;}";

		cssText += "#"+idName+" .goDetail{float:right;margin:0 10px 0 0;}";
		cssText += "#"+idName+" .b_t_d{margin-top:10px;border-top: 1px dotted #d1d1d1;}";


		var STYLE = document.createElement('style');
		STYLE.setAttribute("type", "text/css");
		STYLE.styleSheet && (STYLE.styleSheet.cssText = cssText) || STYLE.appendChild(document.createTextNode(cssText));
		document.getElementsByTagName('head')[0].appendChild(STYLE);
		var liString = "<li><a><img width='"+imgWidth+"px' height='"+imgHeight+"px'/></a><a><span class='productName'></a></span><span class='price'><b>"+(json.isSpecial?"抢购价：":"天宇价：")+"</b><font></font></span><a class='nowBuy hide'>立即购买</a><a class='goDetail hide'>详情</a></li>";
		var $string = $(string);
		var $ul = $string.find("ul");
		
		for (var i=0;i<len; i++){
			var obj = list[i];
			var $li = $(liString);			
			$li.find("img").attr("src",obj.url);
			$li.find(".productName").html(obj.name);
			if(obj.type) {
				$li.find(".price").addClass("b_t_d");
				$li.find(".price font").html("¥"+obj.price+"&nbsp;("+obj.discount+"折)");
				$li.append("<b class='tag'>"+obj.type+"</b>");
			} else {
				$li.find(".price font").html("¥"+obj.price);
				$li.find(".nowBuy,.goDetail").removeClass("hide");
			}
			
			$ul.append($li);
		}
		$ul.append($ul.html());//防止空白出现
		$(this).append($string);
		$(this).find("em").click(function (){
			//alert(moveTime.constructor);
			if(moveTime) window.clearTimeout(moveTime);
			//alert(moveTime.constructor);
			var isLeft = $(this).is(".moveLeftIcon");
			var left = $ul.css("left").replace(/px/g,"");
			left = parseInt(left,10);
			var absleft = Math.abs(left);
			$ul.stop(true,false);
			if(absleft>=ulWidth){
				absleft = absleft-ulWidth;
			}
			if(isLeft){							
											
				var _left = absleft+frameWdith;
				if(_left<(ulWidth-frameWdith)){
					$ul.css("left",-(absleft+ulWidth)).animate({left:-(_left+ulWidth)},500);
				} else if(absleft<(ulWidth-frameWdith)){
					$ul.animate({left:-(ulWidth-frameWdith+ulWidth)},500);
				} else {
					$ul.css("left",-(ulWidth-frameWdith)).animate({left:-ulWidth},500);
				}
			} else {
				var _left =  absleft-frameWdith;
				if(absleft==0){
					$ul.css("left",-ulWidth).animate({left:-(ulWidth-frameWdith)},500);
				} else if(absleft<frameWdith){
					$ul.css("left",-frameWdith).animate({"left":0},500);
				} else {
					$ul.css("left",-absleft).animate({"left":-_left},500);
					
				}
			}
			moveTime = window.setTimeout(_fnMoveMouble,8000,"#"+idName);
		});
		var _isrun = true;
		function _fnMoveMouble(_this){
			if(_isrun){
				if(moveTime) clearTimeout(moveTime);
				$(_this).find(".moveRightIcon").trigger("click");
				moveTime = window.setTimeout(_fnMoveMouble,8000,_this);
			}
			
		}
		var moveTime = window.setTimeout(_fnMoveMouble,8000,this);
		$(this).find("ul").mouseover(function (){
			_isrun = false;
			if(moveTime) clearTimeout(moveTime);
		});
		$(this).find("ul").mouseout(function (){
			if(!_isrun){
				_isrun = true;
				moveTime = window.setTimeout(_fnMoveMouble,8000,"#"+idName);
			}
		});
	};
})(jQuery);